package com.tiany.java_study_exercise;

public class PersonTest {
    public static void main(String[] args){
        Person person=new Person();
        System.out.println(person.getAge());
        person.setAge(15);
        System.out.println(person.getAge());
        person.setAge(189);
        System.out.println(person.getAge());

    }

}
class Person{
    private int age;
    //构造器，设置默认值为18
    public Person(){
        age=18;
    }
    public void setAge(int age){
        if (age>=0&&age<=130){
        this.age=age;
        }else {
            this.age=-1;
        }
    }
    public int getAge(){
        return age;
    }
}
